home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Id: atari.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
- *
- */
-
- /* GNUPLOT - atari.trm */
- /*
- * Copyright (C) 1992
- *
- * Permission to use, copy, and distribute this software and its
- * documentation for any purpose with or without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation.
- *
- * Permission to modify the software is granted, but not the right to
- * distribute the modified code. Modifications are to be distributed
- * as patches to released version.
- *
- * This software is provided "as is" without express or implied warranty.
- *
- * This file is included by ../term.c.
- *
- * This terminal driver supports:
- * Atari Screens working with the normal VDI
- * (this should include TT and big screens)
- *
- * AUTHORS
- * Alexander Lehmann
- * HE Koechling
- *
- * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
- *
- * ATARI-related comments please to alexlehm@iti.informatik.th-darmstadt.de
- *
- */
-
- #ifdef __PUREC__
- /* why did they have to change these names ??? */
- #include <aes.h>
- #include <vdi.h>
- #include <tos.h>
- #else /* !__PUREC__ i.e. __GNUC__, maybe others */
- #include <aesbind.h>
- #include <vdibind.h>
- #include <osbind.h>
- #endif
-
- /* default to hi-res */
-
- #define ATARI_XMAX 640
- #define ATARI_YMAX 400
- #define ATARI_VCHAR 16
- #define ATARI_HCHAR 8
- #define ATARI_HTIC (ATARI_XMAX/100)
- #define ATARI_VTIC ATARI_HTIC
-
- #define ATARI_yc(y) (ATARI_maxycoord-(y))
- #define ATARI_LINETYPES_MAX 11
- static int ATARI_linetypes[ATARI_LINETYPES_MAX] = {
- 0xffff, 0x1111,
- 0xffff, 0x5555, 0x3333, 0x7777,
- 0x3f3f, 0x0f0f, 0x5f5f, 0xe4e4, 0x55f5};
- static int ATARI_lt;
- static int vdi_handle=-1;
- static int ATARI_maxycoord;
- static int ATARI_rotation;
- static int ATARI_numcolors;
- static int pxy[128]; /* Maximum of 64 pixels per v_pline */
- static int pxy_index;
- static int ATARI_colors[16];
- static int ATARI_savecolors[16][3];
- static int ATARI_numpalette;
- #define ATARI_c_height_default 6 /* well, well ... */
- static int ATARI_c_height = ATARI_c_height_default;
-
- ATARI_options( )
- {
- #define ATARIHEXERROR "palette values 3 hex digits, please"
- #define ATARIHEIGHTERROR "expecting a character height"
- char opt[4];
- int i;
- char *tok_end;
-
- term_options[0]='\0';
- ATARI_c_height=ATARI_c_height_default;
-
- for( i=0 ; i<17 ; i++ ) {
- if(END_OF_COMMAND) break;
- if (token[c_token].length>3) {
- ATARI_numpalette=0;
- ATARI_c_height=ATARI_c_height_default;
- term_options[0]='\0';
- int_error(ATARIHEXERROR, c_token);
- }
-
- capture( opt, c_token, c_token );
- if (!i) {
- ATARI_c_height = strtoul( opt, &tok_end, 10 );
- if( *tok_end!='\0' ) {
- ATARI_numpalette=0;
- ATARI_c_height=ATARI_c_height_default;
- term_options[0]='\0';
- int_error(ATARIHEIGHTERROR, c_token);
- }
- if( ATARI_c_height>999 )
- ATARI_c_height=999; /* avoid opt length overflow */
- sprintf( opt, "%d ", ATARI_c_height );
- }
- else {
- ATARI_colors[i-1]=strtoul( opt, &tok_end, 16 );
- if( *tok_end!='\0' ) {
- ATARI_numpalette=0;
- ATARI_c_height=ATARI_c_height_default;
- term_options[0]='\0';
- int_error(ATARIHEXERROR, c_token);
- }
-
- sprintf( opt, "%03X ", ATARI_colors[i-1] );
- }
- strcat( term_options, opt );
- c_token++;
- }
- ATARI_numpalette=(i==0 ? 0 : i-1);
- }
-
- ATARI_init( )
- {
- int work_in[11];
- int work_out[57];
- int i;
- int hchar, wchar, dummy;
- int rgb[3];
- int num_save;
- char *colors,*tok_end;
-
- if( ATARI_numpalette==0 && (colors=getenv("GNUCOLORS")) && *colors ) {
- for( i=0 ; i<17 ; i++ ) {
- if (!i) {
- ATARI_c_height = strtoul( colors, &tok_end, 10 );
- if( colors==tok_end ) {
- i=0;
- ATARI_c_height=ATARI_c_height_default;
- break;
- }
- }
- else {
- if( *colors=='\0' ) break;
- ATARI_colors[i]=strtoul( colors, &tok_end, 16 );
- if( colors==tok_end || (unsigned)ATARI_colors[i]>0xfff ) {
- i=0;
- break;
- }
- }
- colors=tok_end;
-
- while( *colors==' ' ) colors++;
- }
- ATARI_numpalette=(i==0 ? 0 : i-1);
- }
-
- vdi_handle=graf_handle( &wchar, &hchar, &dummy, &dummy );
- if( !vdi_handle )
- int_error("Fatal error opening virtual workstation", NO_CARET);
-
- for( i=0 ; i<10 ; work_in[i++]=1 );
- work_in[10]=2; /* use raster coordinates */
- v_opnvwk( work_in, &vdi_handle, work_out );
- if( !vdi_handle )
- int_error("Fatal error opening virtual workstation", NO_CARET);
-
- vst_height(vdi_handle, ATARI_c_height, &dummy, &dummy, &wchar, &hchar);
-
- vs_clip( vdi_handle, 0, work_in ); /* turn clipping off */
-
- term_tbl[term].xmax=work_out[0]+1;
- term_tbl[term].ymax=work_out[1]+1;
- term_tbl[term].h_char=wchar;
- term_tbl[term].v_char=hchar; /* hchar stands for height this time */
- term_tbl[term].h_tic=(work_out[0]+1)/100;
- term_tbl[term].v_tic=term_tbl[term].h_tic;
-
- ATARI_maxycoord=work_out[1];
- ATARI_numcolors=work_out[13];
- pxy_index=0;
-
- for( i=0 ; i<ATARI_numpalette ; i++ ) {
- vq_color( vdi_handle, i, 1, ATARI_savecolors[i] );
-
- rgb[0]=1000*(ATARI_colors[i]>>8);
- rgb[0]/=15;
- rgb[1]=1000*((ATARI_colors[i]>>4)&15);
- rgb[1]/=15;
- rgb[2]=1000*(ATARI_colors[i]&15);
- rgb[2]/=15;
- vs_color(vdi_handle, i, rgb );
- }
- #ifdef __PUREC__
- /* currently the PureC version runs as .prg and the GCC version runs as .ttp.
- Let's hope that we soon figure out which way is the best */
- v_hide_c(vdi_handle);
- #endif
- }
-
- ATARI_reset( )
- {
- int i;
-
- if( vdi_handle!=-1 ) {
- for( i=0 ; i<ATARI_numpalette ; i++ ) {
- vs_color(vdi_handle, i, ATARI_savecolors[i] );
- }
- #ifdef __PUREC__
- /* see above */
- v_show_c(vdi_handle, 0);
- #endif
- v_clsvwk( vdi_handle );
- vdi_handle=-1;
- }
- }
-
- ATARI_graphics( )
- {
- int pxy[8];
- MFDB mfdb;
-
- fflush( stdout );
- fflush( stderr );
- Cconws( "\033f" ); /* turn cursor off */
- /* apparently v_clrwk doesn't work with overscan. We'll blit the screen clear.
- v_clrwk( vdi_handle );
- */
- mfdb.fd_addr=NULL; /* NULL means actual screen. So we don't need size etc. */
-
- pxy[0]=pxy[4]=0;
- pxy[1]=pxy[5]=0;
- pxy[2]=pxy[6]=term_tbl[term].xmax-1;
- pxy[3]=pxy[7]=term_tbl[term].ymax-1;
-
- vro_cpyfm( vdi_handle, ALL_WHITE /*0*/, pxy, &mfdb, &mfdb );
-
- pxy_index=0;
- }
-
- flush_line( )
- {
- int line_type;
- int color_index;
- int i;
-
- if( pxy_index>=2 ) {
- if( ATARI_numcolors==2 ) { /* Monochrome */
- color_index=1;
- line_type=ATARI_lt;
- if (line_type >= 0)
- line_type %= (ATARI_LINETYPES_MAX - 2);
- } else { /* Color */
- if (ATARI_lt<0) {
- color_index=1;
- line_type= ATARI_lt;
- }
- else {
- color_index=2+ATARI_lt%(ATARI_numcolors-2);
- line_type=(ATARI_lt/(ATARI_numcolors-2)) % (ATARI_LINETYPES_MAX - 2);
- }
- }
-
- vswr_mode( vdi_handle, MD_TRANS);
- vsl_color( vdi_handle, color_index );
-
- vsl_type( vdi_handle, 7 );
- vsl_udsty( vdi_handle, ATARI_linetypes[line_type + 2] );
-
- v_pline( vdi_handle, pxy_index, pxy );
- }
-
- if( pxy_index>=1 ) {
- pxy[0]=pxy[2*(pxy_index-1)];
- pxy[1]=pxy[2*(pxy_index-1)+1];
- pxy_index=1;
- }
- }
-
- ATARI_text( )
- {
- flush_line( );
- Cnecin(); /* wait for any char --> enable screen dump */
- Cconws( "\033e" ); /* turn cursor on again */
- }
-
- ATARI_move( int x, int y )
- {
- flush_line( );
-
- pxy_index=1;
- pxy[0]=x;
- pxy[1]=ATARI_yc(y);
- }
-
- ATARI_vector( int x, int y )
- {
- pxy[2*pxy_index]=x;
- pxy[2*pxy_index+1]=ATARI_yc(y);
- pxy_index++;
-
- if( pxy_index==64 ) { /* we're all full */
- flush_line( );
- }
- }
-
- ATARI_linetype( int lt )
- {
- flush_line( );
-
- ATARI_lt=lt;
- }
-
- ATARI_put_text( int x, int y, char *str )
- {
- int vchar=term_tbl[term].v_char;
- int dummy;
-
- if( !strlen(str) ) return;
-
- if( x<0 ) x=0;
- if( y<0 ) y=0;
-
- /* align text left and to middle of char height */
- vst_alignment( vdi_handle, 0, 5, &dummy, &dummy );
- vst_rotation( vdi_handle, (ATARI_rotation ? 900 : 0) );
- if( ATARI_rotation )
- v_gtext( vdi_handle, x-vchar/2+1, ATARI_yc(y)-1, str );
- else
- v_gtext( vdi_handle, x+1, ATARI_yc(y)-vchar/2+1, str );
- }
-
- TBOOLEAN ATARI_text_angle( int ang )
- {
- ATARI_rotation=ang;
-
- return TRUE;
- }
-
- TBOOLEAN ATARI_justify_text( int mode )
- {
- return FALSE;
- }
-
- ATARI_point( int x, int y, int number )
- {
- int old_linetype;
-
- if( ATARI_numcolors==2 ) {
- line_and_point( x, y, number ); /* monochrome */
- } else {
- /* we map colors that exceed our limit to dotted lines, but we can't do
- that with the markers (sortof a generalized line_and_point) */
- old_linetype=ATARI_lt;
- if( ATARI_lt>ATARI_numcolors-2 )
- ATARI_linetype(ATARI_lt%(ATARI_numcolors-2)); /* same color, but no dots */
- do_point( x, y, number );
- ATARI_linetype(old_linetype);
- }
- }
-